<<<<<<< HEAD
from bll import mengdaili
from dal import database
from config import settings
import requests
import json

if __name__ == '__main__':
    session = requests.Session()
    login_ok = mengdaili.login(session, settings.MENGDAILI['urls']['login_url'], settings.MENGDAILI['user']['username'], settings.MENGDAILI['user']['password'])
    db = database.Database.get_instance()
    if login_ok:
        sign_ok = mengdaili.sign_in(session, settings.MENGDAILI['urls']['signin_url'])
        if sign_ok:
            mengdaili.get_pay_uid(session, settings.MENGDAILI['urls']['pay_url'])
            order_id = mengdaili.get_order(session, settings.MENGDAILI['urls']['order_url'])
            ips = mengdaili.get_ips(session, order_id)
        else:
            try:
                order_id = mengdaili.get_order(session, settings.MENGDAILI['urls']['order_url'])
                ips = mengdaili.get_ips(session, order_id)
                ips = json.loads(ips)
            except:
                uid = mengdaili.get_pay_uid(session, settings.MENGDAILI['urls']['pay_url'], settings.MENGDAILI['pay_types'][1], settings.MENGDAILI['pay_dates'][1])
                mengdaili.hb_pay(session, settings.MENGDAILI['urls']['hb_py_url'], uid)
                order_id = mengdaili.get_order(session, settings.MENGDAILI['urls']['order_url'])
                mengdaili.get_ips(session, order_id)
                ips = mengdaili.get_ips(session, order_id)
                ips = json.loads(ips)
            sql = "insert into meng(ip) values (%s)"
            db.insert(sql, *ips)
=======
from core.proxy_pool import ProxyPool
from estate.fangtianxia import FangTianXia
from dal.database import Database

from multiprocessing import Process


def worker(area, url):
    """
    :param area: 0表示北京，1表示上海，2表示广州
    :param url: 城市的url
    :return:
    """
    proxy_pool = ProxyPool()
    fangtianxia = FangTianXia(area, proxy_pool)
    results = fangtianxia.batch_crawling(url)
    db = Database.get_instance()
    sql = "insert into estate(title, price, area) values(%s, %s, %s)"
    [result.append(area) for result in results]
    db.batch_insert(sql, results) if results else None


if __name__ == "__main__":
    beijing_page_url = "https://esf.fang.com/house/i3"
    shanghai_page_url = "https://sh.esf.fang.com/house/i3"
    guangzhou_page_url = "https://gz.esf.fang.com/house/i3"
    page_urls = [beijing_page_url, shanghai_page_url, guangzhou_page_url]

    processes = []
    for index in range(len(page_urls)):
        process = Process(target=worker, args=(index, page_urls[index]))
        processes.append(process)

    [process.start() for process in processes]
    [process.join() for process in processes]

>>>>>>> 1693903... 利用代理池爬取国内某大型房产平台房价信息
